Conversation
andrewbranch
approved these changes
Oct 28, 2022
andrewbranch
left a comment
Member
There was a problem hiding this comment.
It’s basically impossible to read the emit changes, but the unit test makes it seem like this is right 🤷
Contributor
Author
|
Basically, the only step of ForIn/OfBodyEvaluation that should trigger IteratorClose is an abrupt completion during the evaluation of the iterator statement body. This just adds a variable that is set to Here's a (hopefully) easier to read version where the temp variables have been renamed to indicate their purpose: // source
for await (const x of y) {
...
}
// output
var _done, _value, _errorFromLoopBody, _returnFunction, _result;
try {
var _nonUserCode = true; // start non-user code section
for (var _iter = y[Symbol.asyncIterator](); _result = await _iter.next(), _done = _result.done, !_done;) {
_value = _result.value;
_nonUserCode = false; // end non-user code
// start user code
try {
const x = _value;
...
}
finally {
// end user code
_nonUserCode = true; // start non-user code
}
}
}
catch (error) {
_errorFromLoopBody = { error };
}
finally {
try {
// only call return if abruptly exiting from _user_ code.
if (!_nonUserCode && !_done && (_returnFunction = _iter.return)) {
yield _returnFunction.call(_iter);
}
}
finally {
if (_errorFromLoopBody) throw _errorFromLoopBody.error;
}
}
// end non-user code |
Contributor
Author
|
Looks like this works with main locally. |
This was referenced Feb 14, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This wraps user code in a
for-await-ofstatement so that we only calliter.return()when user code exits abruptly. This better aligns with ForIn/OfBodyEvaluation which only calls IteratorClose when there is an abrupt completion in the body.Fixes #50525